package com.study.other1;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.Date;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * @Author tanglingyu
 * @Date: 2021/08/04/ 15:49
 * @Description
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = BaseTestConfiguration.class)
public class PersonConverterTest2 {

  //这里把转换器装配进来
  @Autowired
  private PersonConverter2 personConverter2;

  @Test
  public void test() {
    Person person = new Person(1L, "tanglingyu", "296017902@qq.com", new Date(), new User(1));
    PersonDTO personDTO = personConverter2.domain2dto(person);

    assertNotNull(personDTO);
    assertEquals(personDTO.getId(), person.getId());
    assertEquals(personDTO.getName(), person.getName());
    assertEquals(personDTO.getBirth(), person.getBirthday());
    String format = DateFormatUtils.format(personDTO.getBirth(), "yyyy-MM-dd HH:mm:ss");
    assertEquals(personDTO.getBirthDateFormat(), format);
    assertEquals(personDTO.getBirthExpressionFormat(), format);

  }
}
